package com.demo.servlet.demo1221.demo01;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

//@WebListener
public class MyListener1 implements ServletContextListener, HttpSessionListener, ServletRequestListener {

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        System.out.println("监听到 ServletContext 对象创建" + sce.getServletContext());
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        System.out.println("监听到 ServletContext 对象销毁");
    }

    @Override
    public void requestDestroyed(ServletRequestEvent sre) {
        System.out.println("监听到 ServletRequest 对象销毁");
    }

    @Override
    public void requestInitialized(ServletRequestEvent sre) {
        System.out.println("监听到 ServletRequest 对象创建");
    }

    @Override
    public void sessionCreated(HttpSessionEvent se) {
//        se.getSession().setMaxInactiveInterval(5);
        System.out.println("监听到 HttpSession 对象创建" + se.getSession().getId());
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        System.out.println("监听到 HttpSession 对象销毁");
    }
}
